﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace Dmo_lc_2.Shape
{
    public class BlockReferenceShape : BaseShape
    {
        public List<BaseShape> mSubEntities = new List<BaseShape>();

        public BlockReferenceShape(Entity in_entity, Transaction tr) : base(in_entity, tr)
        {
        }

        public override void Init()
        {
            shapeType = ShapeType.BLOCKREFERENCE;
            shapeTypeName = shapeType.ToString();

            BlockReference in_shape = (BlockReference)mEntity;

            DBObjectCollection objs = new DBObjectCollection();
            try
            {
                in_shape.Explode(objs);
                foreach (DBObject obj in objs)
                {
                    if (obj is Entity)
                    {
                        Entity entity = obj as Entity;
                        BaseShape bs = ShapeFactory.genShapeByEntity(mTransaction, obj);
                        if (bs != null && bs.shapeType != BaseShape.ShapeType.BASE)
                            mSubEntities.Add(bs);
                    }
                }
            }
            catch (System.Exception ex)
            {
                return;
            }
        }
    }
}
